/*
 * AddCreditAccountPanel.java
 *
 * Created on 2008年5月29日, 下午9:07
 */

package gui;

import abstractmodel.IAccount;
import abstractmodel.IBook;
import abstractmodel.IModelFactory;

/**
 *
 * @author  yux
 */
public class AddCreditAccountPanel extends javax.swing.JPanel {
    private IModelFactory mf = Main.mf;
    IBook book;
    /** Creates new form AddCreditAccountPanel */
    public AddCreditAccountPanel(IBook bk) {
        book=bk;
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldBank = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldNumber = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldBankName = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldBound = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldValid = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldPayDay = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldSlipDay = new javax.swing.JTextField();
        jButtonConfirm = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(800, 600));

        jLabel1.setFont(new java.awt.Font("宋体", 0, 18));
        jLabel1.setText("添加信用卡帐户:");

        jLabel2.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel2.setText("名称");

        jLabel3.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel3.setText("开户银行");

        jLabel4.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel4.setText("卡号");

        jLabel5.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel5.setText("开户名");

        jLabel6.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel6.setText("信用额度");

        jLabel7.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel7.setText("有效日期");

        jLabel8.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel8.setText("还款日期");

        jLabel9.setFont(new java.awt.Font("宋体", 0, 14));
        jLabel9.setText("账单日");

        jButtonConfirm.setFont(new java.awt.Font("宋体", 0, 14));
        jButtonConfirm.setText("确定");
        jButtonConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfirmActionPerformed(evt);
            }
        });

        jButtonCancel.setFont(new java.awt.Font("宋体", 0, 14));
        jButtonCancel.setText("取消");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(153, 153, 153)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel9))
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTextFieldBank)
                                .addComponent(jTextFieldName, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jTextFieldBound, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldBankName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                                    .addComponent(jTextFieldValid, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldSlipDay, javax.swing.GroupLayout.Alignment.LEADING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldPayDay, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(192, 192, 192)
                        .addComponent(jButtonConfirm)
                        .addGap(121, 121, 121)
                        .addComponent(jButtonCancel)))
                .addGap(143, 143, 143))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(jLabel1)
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldBank, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldBankName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldBound, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldPayDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldValid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldSlipDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCancel)
                    .addComponent(jButtonConfirm))
                .addContainerGap(71, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /** 
     * 当输入的所有信息都符合规范时，返回true，否则弹出相应警告框
     * @return
     */
    private boolean checkInfo (javax.swing.JTextField f) {
        if(f.getText() == null || f.getText().equals("") || f.getText().equals(" "))
            return false;
        else
            return true;
    }
    
    private void jButtonConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmActionPerformed
        // TODO add your handling code here:
        IAccount account;
        if (checkInfo(jTextFieldBank) && checkInfo(jTextFieldBank)
                && checkInfo(jTextFieldBank) && checkInfo(jTextFieldBank))
            account = mf.newAccount(abstractmodel.AccountType.CREDITCARD_ACCOUNT_TYPE);
        else 
            return;
        //"帐户名称", "归属银行", "卡号", "开户名", "额度", "有效日期", "还款日期", "帐单日"};
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("归属银行", jTextFieldBank.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("开户名", jTextFieldBankName.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("额度", jTextFieldBound.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("帐户名称", jTextFieldName.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("卡号", jTextFieldNumber.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("还款日期", jTextFieldPayDay.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("帐单日", jTextFieldSlipDay.getText());
        if (checkInfo(jTextFieldBank))
            account.getAccountInfo().setValue("有效日期", jTextFieldValid.getText());
        book.addNewAccount(account);
        jButtonCancelActionPerformed(evt);
    }//GEN-LAST:event_jButtonConfirmActionPerformed

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        // TODO add your handling code here:
        Utilities.cancelDialog(this);
    }//GEN-LAST:event_jButtonCancelActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonConfirm;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextFieldBank;
    private javax.swing.JTextField jTextFieldBankName;
    private javax.swing.JTextField jTextFieldBound;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldNumber;
    private javax.swing.JTextField jTextFieldPayDay;
    private javax.swing.JTextField jTextFieldSlipDay;
    private javax.swing.JTextField jTextFieldValid;
    // End of variables declaration//GEN-END:variables
    
}
